function main(defaultParams) {

    debugger;

    const self = this;
    let formPartEle = this.$$element("form_part_3jhm74");

    if (!formPartEle) return;

    formPartEle.$$getRenderElement().onSave().then((res) => {
        const unitId = res.result.documentNo;

        // 获取文件 ID 和目标文档号列表
        const fileId1 = self.$$("upload_9aurrp").cValue[0];
        const fileId2 = self.$$("upload_47i7m7").cValue[0];
        const toDocumentNoList = validateAndSplit(self.$$("text_input_b7ss15").cValue);

        if (toDocumentNoList.length === 0) {
            console.error("目标文档号列表为空或格式不正确");
            return;
        }

        const toPageId = self.$$("text_input_hf0llm").cValue;

        // 构建保存参数
        const saveFileParams = createSaveFileParams(unitId, toDocumentNoList, toPageId);

        // 使用链式调用处理异步逻辑
        return saveUnitMedia(saveFileParams.upload_9aurrp)
            .then(() => saveUnitMedia(saveFileParams.upload_47i7m7))
            .then(() => {
                const submitPromises = toDocumentNoList.map(documentNo => submitProcess(self, defaultParams, documentNo).then(res => {

                }));
                return Promise.all(submitPromises).then(()=>{
                    // 流程发起成功;
                    // 批量修改状态
                    let params = [{
                        name: "ids", valueContent: ids
                    }, {
                        name: "tableId", valueContent: "t_f5f4ea0ee2de4430b29cbf867c257025"
                    }];

                    let columnData = {
                        "columnDataList": [{
                            "columnId": "f_2e4309c0999f4d79a0704a0578b53a06", "value": "1"
                        }, {"columnId": "f_2e4309c0999f4d79a0704a0578b53a06", "value": "1"}]
                    }
                    updateCardCode(params, columnData)
                    console.log(res);
                });
            });
    }).catch(err => {
        console.error("处理过程中发生错误:", err);
    });
}

function updateCardCode() {
   return new Promise((resolve, reject) => {
       api.DATA_SOURCE_EXECUTE("38f50199-1493-460e-807b-f54b57d3a3bb", "api", params, [], JSON.stringify(columnData)).then((res) => {
           // then() 为调用成功的回调
           if (IsJsonString(res.result) && !JSON.parse(res.result).hasError) {
               self.$message.success("标记成功！");
               tableComp.loading = false; // 将表格置为非loading状态
               tableComp.onRefresh(); // 调用表格的数据刷新动作
           } else {
               self.$message.error(res.result); // 显示错误提示信息
               tableComp.loading = false; // 将表格置为非loading状态
           }
       }).catch(err => {
           self.$message.error(err.message); // 显示错误提示信息
           tableComp.loading = false; // 将表格置为非loading状态
       });
   });
}

/**
 * 校验并分割目标文档号列表
 * @param input - 用户输入的文档号列表
 * @returns {string[]} - 分割后的文档号数组
 */
function validateAndSplit(input) {
    if (!input || typeof input !== "string") return [];
    return input.split(",").map(item => item.trim()).filter(item => item);
}

/**
 * 创建保存文件的参数对象
 * @param unitId - 单元 ID
 * @param toDocumentNoList - 目标文档号列表
 * @param toPageId - 页面 ID
 * @returns {{upload_9aurrp: {}, upload_47i7m7: {}}} - 参数对象
 */
function createSaveFileParams(unitId, toDocumentNoList, toPageId) {
    return {
        upload_9aurrp: {
            unitId, fileId: "upload_9aurrp", toDocumentNoList, toUniqueId: "upload_9aurrp", toPageId
        }, upload_47i7m7: {
            unitId, fileId: "upload_47i7m7", toDocumentNoList, toUniqueId: "upload_47i7m7", toPageId
        }
    };
}

/**
 * 发起流程申请
 * @param self
 * @param defaultParams
 * @param documentNo
 * @returns {Promise<unknown>}
 */
function submitProcess(self, defaultParams, documentNo) {
    return new Promise((resolve, reject) => {
        const queryParams = [{
            name: "pageId", valueContent: 'a7a88151-bd54-42c5-9520-249ebbbe5c45' // 使用常量替代硬编码
        }];
        const jsonParams = {
            documentNo
        };

        api.DATA_SOURCE_EXECUTE("a2b29830-9ef5-437a-8975-476783d4e73f", "api", queryParams, [], JSON.stringify(jsonParams))
            .then(res => {
                if (!res.hasError) {
                    resolve(res);
                } else {
                    reject(new Error(res.message));
                }
            })
            .catch(err => {
                reject(new Error(err.message || "提交流程失败"));
            });
    });
}

/**
 * 保存单元媒体
 * @param params - 保存参数
 * @returns {Promise<*>}
 */
function saveUnitMedia(params) {
    return new Promise((resolve, reject) => {
        api.DATA_SOURCE_EXECUTE("ds_api:62e8fd9a-7797-4626-ba17-9635683e7a74", "api", [], [], JSON.stringify(params))
            .then(res => {
                resolve(res);
            })
            .catch(err => {
                reject(new Error(err.message || "保存媒体失败"));
            });
    });
}
